﻿import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts  1.12
import QtGraphicalEffects 1.12
import QtQuick.Controls.Styles 1.4
import "./utils" as Utils
Rectangle {
    id: infoRect
    Rectangle {
        id: barRect
        width: 266
        height: 643
        color: "#272C39"
        Utils.MyTabBar {
            id: settingsTabbar
            width: parent.width
            height: 69 * 3
            anchors.top: parent.top
            anchors.topMargin: 64
            spacing: 0
            currentIndex: 0
            model: ["运行参数", "手柄控制参数", "使用信息"]
        }
    }

    StackLayout {
        anchors.left: barRect.right
        anchors.right: parent.right
        height: parent.height
        currentIndex: settingsTabbar.currentIndex

        Rectangle {
            color: "#20212C"

            Text{
                x: 31
                y: 22
                color: "#DAEFFF"
                text: "运行参数信息"
                font{
                    family: "Microsoft YaHei"
                    pixelSize: 24
                }
            }

            Rectangle{
                x: 55
                y: 72
                width: 874
                height: 54
                color: "#272C39"
                z:1
                RowLayout{
                    anchors.fill: parent
                    Repeater{
                        model: ["参数名称", "数值", "状态"]
                        Item{
                            width: parent.width/3
                            height: 54
                            Text{
                                anchors.centerIn: parent
                                color: "#DAEFFF"
                                text: modelData
                                font{
                                    family: "Microsoft YaHei"
                                    pixelSize: 24
                                }
                            }
                        }
                    }
                }
            }
            ListView{
                id:lv
                x: 55
                y: 134
                width: 874
                height: 551
                spacing: 9
                property int test : 4;
                delegate: Rectangle{
                    width: parent.width
                    height: 54
                    color: "#272C39"
                    RowLayout{
                        anchors.fill: parent
                        Repeater{
                            model: [iname, idata, istate]
                            Item{
                                width: parent.width/3
                                height: 54
                                Text{
                                    anchors.centerIn: parent
                                    color: "#DAEFFF"
                                    text: modelData
                                    font{
                                        family: "Microsoft YaHei"
                                        pixelSize: 24
                                    }
                                }
                            }
                        }
                    }

                }
                ScrollBar.vertical: ScrollBar {       //滚动条
                    anchors.left: parent.right
                    width: 11
                    active: true
                    height: 190
                    contentItem: Rectangle {
                        radius: 9        //bar的圆角
                        color: "#29D2EAFF"
                    }
                }
                model:ListModel{
                    id: fruitModel
                }
                function updata(){
                    fruitModel.clear()
                    if(infoRect.state === "grader"){
                        fruitModel.append({iname: "机油压力",idata: String(can_manager.engine_lubricating_oil_pressure+" bar"),istate: "正常"})
                        fruitModel.append({iname: "冷却水温",idata: String(can_manager.engine_water_temperature+" °C"),istate: "正常"})
                        fruitModel.append({iname: "发动机转速",idata: String(can_manager.engine_speed.toFixed(0)+" r/min"),istate: "正常"})
                        fruitModel.append({iname: "蓄电池电压",idata: String(can_manager.system_voltage.toFixed(1)+" V"),istate: "正常"})
                        fruitModel.append({iname: "行驶速度",idata: String(can_manager.speed.toFixed(0)+" km/h"),istate: "正常"})
                        fruitModel.append({iname: "油位",idata: String(can_manager.fuel_level.toFixed(0)+" %"),istate: "正常"})
                        fruitModel.append({iname: "档位",idata: String(can_manager.gearbox_gear_size),istate: "正常"})
                        fruitModel.append({iname: "变矩器压力",idata: String(can_manager.torque_converter_oil_pressure.toFixed(0)+" bar"),istate: "正常"})
                    }else if(infoRect.state === "loader"){
                        fruitModel.append({iname: "机油压力",idata: String(can_manager.engine_oil_pressure+" bar"),istate: "正常"})
                        fruitModel.append({iname: "发动机冷却水温度",idata: String(can_manager.engine_cooling_water_temperature+" °C"),istate: "正常"})
                        fruitModel.append({iname: "发动机转速",idata: String(can_manager.engine_speed.toFixed(0)+" r/min"),istate: "正常"})
                        fruitModel.append({iname: "蓄电池电压",idata: String(can_manager.battery_voltage.toFixed(1)+" V"),istate: "正常"})
                        fruitModel.append({iname: "发动机累计工作时间",idata: String(can_manager.engine_work_time.toFixed(0)+"h"),istate: "正常"})
                        fruitModel.append({iname: "燃油油位",idata: String(can_manager.fuel_level.toFixed(0)+" %"),istate: "正常"})
                        fruitModel.append({iname: "变速箱油温",idata: String(can_manager.transmission_oil_temperature+" °C"),istate: "正常"})
                        fruitModel.append({iname: "燃油消耗量",idata: String(can_manager.fuel_cost.toFixed(0)),istate: "正常"})
                    }
                }
                Timer {
                    id: tim;
                    interval: 100;          //间隔1s
                    running: false;         //开启，则立即启动
                    repeat: true             //开启循环
                    triggeredOnStart: true;  //启动后，将立即触发一次
                    property int seconds : 4;
                    onTriggered: {
                        lv.updata()
                    }
                }
                Component.onCompleted: {
                    tim.start()
                }

            }

        }

        Rectangle {
            color: "#20212C"

            Text{
                x: 31
                y: 22
                color: "#DAEFFF"
                text: "手柄控制参数信息"
                font{
                    family: "Microsoft YaHei"
                    pixelSize: 24
                }
            }

            Rectangle{
                x: 55
                y: 72
                width: 874
                height: 54
                color: "#272C39"
                RowLayout{
                    anchors.fill: parent
                    Repeater{
                        model: ["参数名称", "数值", "状态"]
                        Item{
                            width: parent.width/3
                            height: 54
                            Text{
                                anchors.centerIn: parent
                                color: "#DAEFFF"
                                text: modelData
                                font{
                                    family: "Microsoft YaHei"
                                    pixelSize: 24
                                }
                            }
                        }


                    }
                }
            }
            ListView{
                x: 55
                y: 134
                width: 874
                height: 551
                spacing: 9

                delegate: Rectangle{
                    width: parent.width
                    height: 54
                    color: "#272C39"
                    RowLayout{
                        anchors.fill: parent
                        Repeater{
//                            model: [iname, idata, istate]
                            Item{
                                width: parent.width/3
                                height: 54
                                Text{
                                    anchors.centerIn: parent
                                    color: "#DAEFFF"
                                    text: modelData
                                    font{
                                        family: "Microsoft YaHei"
                                        pixelSize: 24
                                    }
                                }
                            }
                        }
                    }
                }
            }

        }

        Rectangle {
            color: "#20212C"

            Text{
                x: 31
                y: 22
                color: "#DAEFFF"
                text: "使用信息"
                font{
                    family: "Microsoft YaHei"
                    pixelSize: 24
                }
            }

            Rectangle{
                x: 55
                y: 72
                width: 874
                height: 54
                color: "#272C39"
                RowLayout{
                    anchors.fill: parent
                    Repeater{
                        model: ["参数名称", "数值", "状态"]
                        Item{
                            width: parent.width/3
                            height: 54
                            Text{
                                anchors.centerIn: parent
                                color: "#DAEFFF"
                                text: modelData
                                font{
                                    family: "Microsoft YaHei"
                                    pixelSize: 24
                                }
                            }
                        }


                    }
                }
            }
            ListView{
                x: 55
                y: 134
                width: 874
                height: 551
                spacing: 9

                delegate: Rectangle{
                    width: parent.width
                    height: 54
                    color: "#272C39"
                    RowLayout{
                        anchors.fill: parent
                        Repeater{
                            model: [iname, idata, istate]
                            Item{
                                width: parent.width/3
                                height: 54
                                Text{
                                    anchors.centerIn: parent
                                    color: "#DAEFFF"
                                    text: modelData
                                    font{
                                        family: "Microsoft YaHei"
                                        pixelSize: 24
                                    }
                                }
                            }
                        }
                    }
                }
                //                model: ListModel{
                //                    ListElement{
                //                        iname: "右铲刀"
                //                        idata: "0.0bar"
                //                        istate: "低"
                //                    }
                //                }
            }

        }

    }


}

